home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue28 / vcard / VCARD.ZIP / Msvcard.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-10-13  |  5.0 KB  |  195 lines

  1. unit Msvcard;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, Windows, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, msvcls;
  8.  
  9. type
  10.   TmsVCard = class(TComponent)
  11.   private
  12.     { Private declarations }
  13.     FIdentification : TmsIdentification;
  14.     FDeliveryInfo : TmsDeliveryInfo;
  15.     FTelecomInfo : TmsTelecomInfo;
  16.     FBusinessInfo : TmsBusinessInfo;
  17.     FExplanatoryInfo : TmsExplanatoryInfo;
  18.     procedure SetIdentification(Value : TmsIdentification);
  19.     procedure SetDeliveryInfo(Value : TmsDeliveryInfo);
  20.     procedure SetTelecomInfo(Value : TmsTelecomInfo);
  21.     procedure SetBusinessInfo(Value : TmsBusinessInfo);
  22.     procedure SetExplanatoryInfo(Value : TmsExplanatoryInfo);
  23.   protected
  24.     { Protected declarations }
  25.   public
  26.     { Public declarations }
  27.     constructor Create(AOwner : TComponent); override;
  28.     destructor Destroy; override;
  29.     procedure Clear;
  30.     procedure Assign(Value : TPersistent); override;
  31.     procedure LoadFromStream(Stream : TStream);
  32.     procedure SaveToStream(Stream : TStream);
  33.     procedure LoadFromFile(const FileName : string);
  34.     procedure SaveToFile(const FileName : string);
  35.   published
  36.     { Published declarations }
  37.     property Identification : TmsIdentification read FIdentification
  38.        write SetIdentification;
  39.     property DeliveryInfo : TmsDeliveryInfo read FDeliveryInfo
  40.        write SetDeliveryInfo;
  41.     property TelecomInfo : TmsTelecomInfo read FTelecomInfo
  42.        write SetTelecomInfo;
  43.     property BusinessInfo : TmsBusinessInfo read FBusinessInfo
  44.        write SetBusinessInfo;
  45.     property ExplanatoryInfo : TmsExplanatoryInfo read FExplanatoryInfo
  46.        write SetExplanatoryInfo;
  47.   end;
  48.  
  49. procedure Register;
  50.  
  51. implementation
  52.  
  53. procedure Register;
  54. begin
  55.   RegisterComponents('ArGoSoft', [TmsVCard]);
  56. end;
  57.  
  58. constructor TmsVCard.Create(AOwner : TComponent);
  59. begin
  60.   inherited Create(AOwner);
  61.   FIdentification:=TmsIdentification.Create;
  62.   FDeliveryInfo:=TmsDeliveryInfo.Create;
  63.   FTelecomInfo:=TmsTelecomInfo.Create;
  64.   FBusinessInfo:=TmsBusinessInfo.Create;
  65.   FExplanatoryInfo:=TmsExplanatoryInfo.Create;
  66. end;
  67.  
  68. destructor TmsVCard.Destroy;
  69. begin
  70.   FExplanatoryInfo.Free;
  71.   FBusinessInfo.Free;
  72.   FTelecomInfo.Free;
  73.   FDeliveryInfo.Free;
  74.   FIdentification.Free;
  75.   inherited Destroy;
  76. end;
  77.  
  78. procedure TmsVCard.SetIdentification(Value : TmsIdentification);
  79. begin
  80.   FIdentification.Assign(Value);
  81. end;
  82.  
  83. procedure TmsVCard.SetDeliveryInfo(Value : TmsDeliveryInfo);
  84. begin
  85.   FDeliveryInfo.Assign(Value);
  86. end;
  87.  
  88. procedure TmsVCard.SetTelecomInfo(Value : TmsTelecomInfo);
  89. begin
  90.   FTelecomInfo.Assign(Value);
  91. end;
  92.  
  93. procedure TmsVCard.SetBusinessInfo(Value : TmsBusinessInfo);
  94. begin
  95.   FBusinessInfo.Assign(Value);
  96. end;
  97.  
  98. procedure TmsVCard.SetExplanatoryInfo(Value : TmsExplanatoryInfo);
  99. begin
  100.   FExplanatoryInfo.Assign(Value);
  101. end;
  102.  
  103. procedure TmsVCard.Clear;
  104. begin
  105.   FIdentification.Clear;
  106.   FDeliveryInfo.Clear;
  107.   FTelecomInfo.Clear;
  108.   FBusinessInfo.Clear;
  109.   FExplanatoryInfo.Clear;
  110. end;
  111.  
  112. procedure TmsVCard.Assign(Value : TPersistent);
  113. begin
  114.   if Value is TmsVCard then
  115.   begin
  116.     FIdentification.Assign((Value as TmsVCard).Identification);
  117.     FDeliveryInfo.Assign((Value as TmsVCard).DeliveryInfo);
  118.     FTelecomInfo.Assign((Value as TmsVCard).TelecomInfo);
  119.     FBusinessInfo.Assign((Value as TmsVCard).BusinessInfo);
  120.     FExplanatoryInfo.Assign((Value as TmsVCard).ExplanatoryInfo);
  121.   end
  122.   else
  123.     inherited Assign(Value);
  124. end;
  125.  
  126. procedure TmsVCard.LoadFromStream(Stream : TStream);
  127. var
  128.   Lines : TStrings;
  129. begin
  130.   Lines:=TStringList.Create;
  131.   try
  132.     Stream.Position:=0;
  133.     Lines.LoadFromStream(Stream);
  134.     FIdentification.LoadFromStrings(Lines);
  135.     FDeliveryInfo.LoadFromStrings(Lines);
  136.     FTelecomInfo.LoadFromStrings(Lines);
  137.     FBusinessInfo.LoadFromStrings(Lines);
  138.     FExplanatoryInfo.LoadFromStrings(Lines);
  139.   finally
  140.     Lines.Free;
  141.   end;
  142. end;
  143.  
  144. procedure TmsVCard.SaveToStream(Stream : TStream);
  145. var
  146.   Lines : TStrings;
  147.   s : string;
  148.   i : Integer;
  149. begin
  150.   Lines:=TStringList.Create;
  151.   try
  152.     Lines.Add('BEGIN:VCARD');
  153.     Lines.Add('VERSION:1.2');
  154.     FIdentification.SaveToStrings(Lines);
  155.     FDeliveryInfo.SaveToStrings(Lines);
  156.     FTelecomInfo.SaveToStrings(Lines);
  157.     FBusinessInfo.SaveToStrings(Lines);
  158.     FExplanatoryInfo.SaveToStrings(Lines);
  159.     Lines.Add('END:VCARD');
  160.     for i:=0 to Lines.Count-1 do
  161.     begin
  162.       s:=Concat(Lines[i],^M^J);
  163.       Stream.Write(s[1],Length(s));
  164.     end;
  165.   finally
  166.     Lines.Free;
  167.   end;
  168. end;
  169.  
  170. procedure TmsVCard.LoadFromFile(const FileName : string);
  171. var
  172.   FileStream : TStream;
  173. begin
  174.   FileStream:=TFileStream.Create(FileName, fmOpenRead);
  175.   try
  176.     LoadFromStream(FileStream);
  177.   finally
  178.     FileStream.Free;
  179.   end;
  180. end;
  181.  
  182. procedure TmsVCard.SaveToFile(const FileName : string);
  183. var
  184.   FileStream : TStream;
  185. begin
  186.   FileStream:=TFileStream.Create(FileName, fmOpenWrite or fmCreate);
  187.   try
  188.     SaveToStream(FileStream);
  189.   finally
  190.     FileStream.Free;
  191.   end;
  192. end;
  193.  
  194. end.
  195.